top=..
SRC=./src
CFLAGS= -ansi  -pedantic-errors -Wall -Werror 
CFLAGS= -D _GNU_SOURCE
COMPILEONLY= -c 
BIN=bin
OBJ=obj
CM=Common
PB=Public
ST=Static
DN=Dinamic
RL=../$(CM)/$(BIN)/Release

CC=gcc




Debug:   Debug_OR_Release=Debug
Debug:   CFLAGS+=-g 
Debug:   SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Debug:   OBJ_F=$(OBJ)/$(Debug_OR_Release)

Release: Debug_OR_Release=Release
Release: CFLAGS+=-DNDEBUG -O2
Release: SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Release: OBJ_F=$(OBJ)/$(Debug_OR_Release)



all: Debug

Debug:   create_folders  ftplient  Install  cleanDebug 
Release: create_folders  ftplient  Install  cleanRelease




ftplient: show_action  ftpclient.obj
	g++ -o ./ftpclients.exe ./$(OBJ_F)/*.o 
show_action:
	@echo
	@echo "-----------------------------------"
	@echo "   PRODUCING FTP client executable"
	@echo "-----------------------------------"
	@echo



ftpclient.obj  : $(SRC)/genericclient/genericclient.c  $(SRC)/genericclient/generclient.h $(SRC)/ftpclient/ftpclient.c $(SRC)/ftpclient/internalftpclient.h\
                     ../ftpprotocol/ftpprotocol.c ../ftpprotocol/ftpprotocol.h
	$(CC)  $(CFLAGS) -I $(SRC)/genericclient  -I $(SRC)/ftpclient/  -I ../../$(CM)/$(PB) -I ../ftpprotocol -c $(SRC)/genericclient/genericclient.c\
	 -o $(OBJ_F)/genericclient.o
	$(CC)  $(CFLAGS) -I $(SRC)/genericclient  -I $(SRC)/ftpclient/  -I ../../$(CM)/$(PB) -I ../ftpprotocol  -c $(SRC)/ftpclient/ftpclient.c\
	 -o $(OBJ_F)/ftpclient.o
	$(CC)  $(CFLAGS) -I $(SRC)/genericclient  -I $(SRC)/ftpclient/  -I ../../$(CM)/$(PB) -I ../ftpprotocol  -c ../ftpprotocol/ftpprotocol.c\
	 -o $(OBJ_F)/ftpprotocol.o


create_folders:
	mkdir -p $(OBJ)/$(Debug_OR_Release) 
	mkdir -p $(BIN)/$(Debug_OR_Release)

Install:creat_instal_folders  CopyHfile 


CopyF: 
	cp $(BIN)/$(Debug_OR_Release)/libftpclient.a   ../$(CM)/$(BIN)/$(Debug_OR_Release)

CopyHfile:
	cp $(SRC)/genericclient/generclient.h  ../../Common/$(PB)
	cp $(SRC)/genericclient/generclient.h  ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/FTPClient/src/genericclient/
	cp $(SRC)/genericclient/genericclient.c  ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/FTPClient/src/genericclient/
	cp $(SRC)/ftpclient/internalftpclient.h ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/FTPClient/src/genericclient/
	cp $(SRC)/ftpclient/ftpclient.c		 ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/FTPClient/src/ftpclient
	cp ../ftpprotocol/ftpprotocol.h  	 ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/ftpprotocol
	cp ../ftpprotocol/ftpprotocol.c        ../../../FOR_CUSTOMER/FTPSERVER/FTPserver/ftpprotocol

creat_instal_folders:
	mkdir -p ../../$(CM)/$(PB)
	mkdir -p ../../$(CM)/$(BIN)/$(Debug_OR_Release)


cleanDebug:
	for i in $(SUBDIRS); do\
		(cd $$i);\
	done
	rm -f ./*.o

cleanRelease:
	for i in $(SUBDIRS); do\
		(cd $$i; rm -f* );\
	done
	rm -f ./*.o

